package org.videopractice.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import org.videopractice.R;
import org.videopractice.databinding.DialogAuthorizedPromptBinding;

public class AuthorizedPromptDialog extends Dialog {

    private final DialogAuthorizedPromptBinding bindingView;

    private View.OnClickListener listener;

    public static AuthorizedPromptDialog build(Context context){
        return new AuthorizedPromptDialog(context);
    }

    private AuthorizedPromptDialog(@NonNull Context context) {
        super(context, R.style.CustomDialog_Prompt);
        LayoutInflater inflater = LayoutInflater.from(context);
        View rootView = inflater.inflate(R.layout.dialog_authorized_prompt,null);
        bindingView = DataBindingUtil.bind(rootView);
        bindingView.setAuthorizedPromptDialog(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindingView.getRoot());
        setCancelable(false);
    }

    public AuthorizedPromptDialog setGoAuthorizedBtnOnClickListener(View.OnClickListener listener){
        this.listener = listener;
        return this;
    }

    public void cancelBtnOnClick(View view){
        cancel();
    }

    public void goAuthorizedBtnOnClick(View view){
        dismiss();
        if(listener != null)
            this.listener.onClick(view);
    }

}
